package com.wiscamp.ninechapters.problems.math;

import com.wiscamp.ninechapters.common.core.DateTimeHelper;
import com.wiscamp.ninechapters.common.core.ParseHelper;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

/**
 * 日期
 */
@Data
public class LatexDate implements Serializable {
    private int year = 0;

    private int month = 0;

    private int day = 0;

    public static final String DATE_PATTERN = "yyyy-MM-dd";

    private LocalDate date = null;

    public String getLatex() {
        return date.format(DateTimeFormatter.ofPattern(DATE_PATTERN));
    }

    public LatexDate(int year, int month, int day) {
        this.date = ParseHelper.dateOf(year, month, day);

        if (Objects.nonNull(this.date)) {
            this.year = year;
            this.month = month;
            this.day = day;
        }
    }

    public LatexDate(String content) {
        var date = DateTimeHelper.parseDate(content);
        if (Objects.nonNull(date)) {
            this.year = date.getYear();
            this.month = date.getMonthValue();
            this.day = date.getDayOfMonth();
            this.date = date;
        }
    }
}
